import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession

object zy2 {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("app")
    val spark = SparkSession.builder().config(sparkConf).getOrCreate()

    val aa = spark.read.csv("data/Movie").toDF("name","fen","ren","type","begin","end")
    //aa.show()
//使用SparkSql读取以上数据，注册成Movie表

    aa.createTempView("movie")

    //使用SparkSql统计上映日期最长的电影信息
    //spark.sql("select * from Movie").show()

    spark.sql("select * from movie order by datediff('end','begin') desc limit 1 ").show()
  //使用SparkSql统计2017年上映且观影人数最多的电影信息
    spark.sql("select * from movie where year('begin')=2017 order by '评价人数' desc limit 1").show()
//
//    //使用SparkSql统计2010年-2018年上映且类型为剧情片的所有电影信息
//    spark.sql("select * from Movie where year(to_date('上映日期')) between 2010 and 2018 and '类型' like '%剧情%'").show()
//
//    //使用SparkSql读取数据注册临时表后统计影片的评价总人数和评总和
//
//    spark.sql("select sum('评价人数'),sum('评分') from Movie").show()

    sparkConf.clone()
    spark.stop()

  }
}
